import unittest
import requests
from 其他.学习.jiekou.demo2 import Test_Login


# 通用断言方法
def common_assert(self, resp, status_code, username, code):
    self.assertEqual(status_code, resp.status_code)
    self.assertEqual(username, resp.json().get("username"))
    self.assertEqual(code, resp.json().get("code"))


class TestMmtLogin(unittest.TestCase):
    session = None

    @classmethod
    def setUpClass(cls) -> None:
        cls.session = requests.session()
        print('22222')

    def test_01(self):
        # 调用自己封装的接口，获取验证码
        Test_Login.get_verify(self.session)
        # 调用自己封装的接口，登录
        params = {"username": "food",
                  "password": "96e79218965eb72c92a549dd5a330112",
                  "scene": "LOGIN",
                  "captcha": 1111,
                  "uuid": "8e20ddd0-ac16-11ed-9172-39cda48efa3c"}
        resp = Test_Login.login_success(self.session, params)
        print(resp.json())
        common_assert(self, resp, 200, 'food', None)

    def test_02(self):
        # 调用自己封装的接口，获取验证码
        Test_Login.get_verify(self.session)
        # 调用自己封装的接口，登录
        params1 = {"username": "food11",
                   "password": "96e79218965eb72c92a549dd5a330112",
                   "scene": "LOGIN",
                   "captcha": 1111,
                   "uuid": "8e20ddd0-ac16-11ed-9172-39cda48efa3c"}
        resp = Test_Login.login_success(self.session, params1)
        print(resp.json())

    @classmethod
    def tearDownClass(cls) -> None:
        print("11111")
